//
// File: wavelet.cpp
//
// MATLAB Coder version            : 5.4
// C/C++ source code generated on  : 25-Apr-2025 12:42:26
//

// Include Files
#include "wavelet.h"
#include "freqDomainHRV_types.h"
#include "ifft.h"
#include "rt_nonfinite.h"
#include "coder_array.h"
#include <string.h>

// Function Definitions
//
// Arguments    : coder::array<double, 2U> &in1
//                const struct9_T *in2
// Return Type  : void
//
void binary_expand_op(coder::array<double, 2U> &in1, const struct9_T *in2)
{
  coder::array<double, 2U> b_in1;
  int i;
  int loop_ub;
  int stride_0_1;
  int stride_1_1;
  if (in2->wav.hrv.aVLF.size(1) == 1) {
    i = in1.size(1);
  } else {
    i = in2->wav.hrv.aVLF.size(1);
  }
  b_in1.set_size(1, i);
  stride_0_1 = (in1.size(1) != 1);
  stride_1_1 = (in2->wav.hrv.aVLF.size(1) != 1);
  if (in2->wav.hrv.aVLF.size(1) == 1) {
    loop_ub = in1.size(1);
  } else {
    loop_ub = in2->wav.hrv.aVLF.size(1);
  }
  for (i = 0; i < loop_ub; i++) {
    b_in1[i] = -in1[i * stride_0_1] / 2.0 *
               static_cast<double>(in2->wav.hrv.aVLF[i * stride_1_1] > 0.0);
  }
  in1.set_size(1, b_in1.size(1));
  loop_ub = b_in1.size(1);
  for (i = 0; i < loop_ub; i++) {
    in1[i] = b_in1[i];
  }
}

//
// Arguments    : coder::array<creal_T, 2U> &in1
//                int in2
//                const coder::array<creal_T, 2U> &in3
//                double in4
//                const coder::array<double, 2U> &in5
//                const struct9_T *in6
// Return Type  : void
//
void binary_expand_op(coder::array<creal_T, 2U> &in1, int in2,
                      const coder::array<creal_T, 2U> &in3, double in4,
                      const coder::array<double, 2U> &in5, const struct9_T *in6)
{
  coder::array<creal_T, 2U> b_in3;
  coder::array<creal_T, 2U> r;
  int i;
  int loop_ub;
  int stride_0_1;
  int stride_1_1;
  int stride_2_1;
  if (in6->wav.hrv.aVLF.size(1) == 1) {
    i = in5.size(1);
  } else {
    i = in6->wav.hrv.aVLF.size(1);
  }
  if (i == 1) {
    i = in3.size(1);
  } else if (in6->wav.hrv.aVLF.size(1) == 1) {
    i = in5.size(1);
  } else {
    i = in6->wav.hrv.aVLF.size(1);
  }
  b_in3.set_size(1, i);
  stride_0_1 = (in3.size(1) != 1);
  stride_1_1 = (in5.size(1) != 1);
  stride_2_1 = (in6->wav.hrv.aVLF.size(1) != 1);
  if (in6->wav.hrv.aVLF.size(1) == 1) {
    i = in5.size(1);
  } else {
    i = in6->wav.hrv.aVLF.size(1);
  }
  if (i == 1) {
    loop_ub = in3.size(1);
  } else if (in6->wav.hrv.aVLF.size(1) == 1) {
    loop_ub = in5.size(1);
  } else {
    loop_ub = in6->wav.hrv.aVLF.size(1);
  }
  for (i = 0; i < loop_ub; i++) {
    double d;
    double d1;
    d = in6->wav.hrv.aVLF[i * stride_2_1];
    d1 = in4 * in5[i * stride_1_1];
    b_in3[i].re = d1 * static_cast<double>(d > 0.0) * in3[i * stride_0_1].re;
    b_in3[i].im = d1 * static_cast<double>(d > 0.0) * in3[i * stride_0_1].im;
  }
  coder::ifft(b_in3, r);
  loop_ub = r.size(1);
  for (i = 0; i < loop_ub; i++) {
    in1[in2 + 449 * i] = r[i];
  }
}

//
// File trailer for wavelet.cpp
//
// [EOF]
//
